package com.cq.hd.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cq.hd.order.api.dto.*;
import com.cq.hd.order.api.vo.*;
import com.cq.hd.order.param.AgentActiveCommissionParam;
import com.cq.hd.order.param.SubOrderStateUpdateParam;
import com.cq.hd.order.po.TbOrderItemPo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 订单项表 Mapper 接口
 * </p>
 *
 * @author mYunYu
 * @since 2023-12-13
 */
@Mapper
public interface TbOrderItemMapper extends BaseMapper<TbOrderItemPo> {

    List<AppOrderItemVo> listByOrderId(@Param("orderId") Long orderId);

    int updateCancelByOrderId(@Param("orderId") Long orderId, @Param("now") LocalDateTime now);

    List<AdminOrderItemVo> listAdminOrderItemByOrderIds(@Param("orderIds") List<Long> orderIds);

    AdminOrderItemVo getOrderItemBySubOrderNo(@Param("subOrderNo") String subOrderNo);

    List<MerchantOrderPageVo> listMerchantOrderByDto(MerchantOrderPageDto merchantOrderPageDto);

    MerchantOrderDetailVo detailMerchantOrder(@Param("orderItemId") Long orderItemId, @Param("merchantId") Long merchantId);

    MerchantVerifyConfirmVo getByVerifyCode(@Param("verifyCode") String verifyCode);

    List<MerchantVerifyRecordPageVo> listVerifyRecordByDto(MerchantVerifyRecordPageDto merchantVerifyRecordPageDto);

    List<AdminVerifyRecordPageVo> listAdminVerifyRecordByDto(ActiveVerifyRecordQueryDto activeVerifyRecordQueryDto);

    List<ActiveVerifyMerchantVo> listVerifyMerchant(@Param("activeId") Long activeId);

    List<MerchantVerifyGoodsPageVo> listVerifyGoodsByDto(MerchantVerifyGoodsPageDto merchantVerifyGoodsPageDto);

    List<MerchantVerifyGoodsDetailPageVo> listVerifyGoodsDetailByDto(MerchantVerifyGoodsDetailPageDto merchantVerifyGoodsDetailPageDto);

    List<OrderItemVo> listByActiveIds(@Param("activeIds") List<Long> activeIds);

    List<OrderItemVo> listByDto(OrderItemDto orderItemDto);

    int updateSubOrderStateByOrderId(@Param("orderId") Long orderId, @Param("subOrderState") Integer subOrderState);

    int updateExpireByOrderId(@Param("orderId") Long orderId, @Param("now") LocalDateTime now);

    int updatePftResult(@Param("id") Long id, @Param("pftOrder") String pftOrder, @Param("verifyCode") String verifyCode);

    void updateReturnAmt(@Param("id") Long id, @Param("returnAmt") BigDecimal returnAmt, @Param("merchantAmt") BigDecimal merchantAmt);

    // 统计商户待结算订单商品本金 & 补贴
    MerchantOrderAmtStatVo sumMerchantWaitSettleAmt(Long merchantId);

    int updateSubState(SubOrderStateUpdateParam subOrderStateUpdateParam);

    // 查询待结算的子单
    List<TbOrderItemPo> selectUnSettleOrderItems(@Param("endVerifyTime") LocalDateTime endVerifyTime);

    List<AgentRankItemVo> getAgentActiveCommission(AgentActiveCommissionParam agentActiveCommissionParam);

    MerchantOrderStatisticsVo statisticsMerchantOrder(MerchantOrderPageDto merchantOrderPageDto);

    // 查询积分待结算的子订单
    List<OrderItemPointsVo> selectUnSettlePointsOrderItems();

    // 查询积分待结算的订单（根据子单积分结算状态查询）
    List<OrderPointsVo> selectUnSettlePointsOrders();

    // 更新子订单积分结算状态
    int updatePointsSettleState(@Param("id") Long id);

    // 更新子订单积分结算状态
    int updatePointsSettleStateByOrderId(@Param("orderId") Long orderId);

    // 更新子订单佣金结算状态
    int updateCommissionSettleStateByOrderId(@Param("orderId") Long orderId);

}
